package com.bolt.auth.security.admin.biz.rpc;

import com.bolt.auth.admin.api.feign.RemoteUserService;
import com.bolt.auth.admin.api.sys.dto.UserInfo;
import com.bolt.auth.admin.api.sys.entity.LoginLogEntity;
import com.bolt.auth.admin.api.sys.entity.UserEntity;
import com.bolt.auth.security.admin.biz.sys.service.LoginLogService;
import com.bolt.auth.security.admin.biz.sys.service.UserService;
import com.bolt.auth.security.common.annotation.IgnoreFilter;
import com.bolt.convention.data.ResultMessage;
import com.bolt.convention.data.Results;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping()
@Slf4j
public class UserController implements RemoteUserService {

    @Autowired
    private UserService userService;

    @Autowired
    private LoginLogService loginLogService;

    @Override
    @IgnoreFilter
    public ResultMessage <UserInfo> findByUserName(@PathVariable("username") String username) {
        UserEntity user = userService.findByUserName(username);
        UserInfo userInfo = userService.userInfo(user);
        return Results.success(userInfo);
    }


    @Override
    @IgnoreFilter
    public ResultMessage saveUserLoginLog(@RequestBody LoginLogEntity loginLogEntity) {
        return Results.success(loginLogService.save(loginLogEntity));
    }

}

 